package com.moore.controller;

import com.moore.bean.CareerIntentions;
import com.moore.dto.ResponseData;
import com.moore.service.IntentionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("/intentions")
public class IntentionsController {
    @Autowired
    private IntentionsService intentionsService;

    @GetMapping("/get")
    public ResponseData getIntentions(int userId){
        List<CareerIntentions> intentions = intentionsService.getCareerIntentionsByUserId(userId);
        return ResponseData.returnList("查询成功",intentions, intentions.size());
    }

    @GetMapping("/getById")
    public ResponseData getIntentionsById(int id){
        CareerIntentions intentions = intentionsService.getCareerIntentionsById(id);
        return ResponseData.returnObject("查询成功",intentions);
    }

    @GetMapping("/delete")
    public ResponseData deleteIntentions(int id){
        int result = intentionsService.deleteCareerIntentionsById(id);
        if(result > 0) return ResponseData.ok("删除成功");
        else return ResponseData.error("删除失败");
    }

    @PostMapping("/save")
    public ResponseData addIntentions(@RequestBody CareerIntentions intentions){
        int result = intentionsService.saveCareerIntentions(intentions);
        if(result > 0) return ResponseData.ok("添加成功");
        else return ResponseData.error("添加失败");
    }
}
